跳转至

ui/base/device_pixel.h

Device pixel ratio conversion utilities for canvas units. More...

Namespaces

Name
cf
cf::ui
cf::ui::base
cf::ui::base::device

Classes

Name
struct cf::ui::base::device::CanvasUnitHelper
Helper for converting between canvas units and device pixels.

Detailed Description

Device pixel ratio conversion utilities for canvas units.

Author: Charliechen114514

Version: 0.1

Since: 0.1

Date: 2026-02-23

Provides helper structures and functions for converting between device-independent pixels (dp), scalable pixels (sp), and physical pixels based on device pixel ratio.

Source code

#pragma once
#include <QtTypes>

namespace cf::ui::base {
namespace device {

struct CanvasUnitHelper {
    CanvasUnitHelper(const qreal devicePixelRatio);

    qreal dpToPx(qreal dp) const;

    qreal spToPx(qreal sp) const;

    qreal pxToDp(qreal px) const;

    qreal dpi() const;

    enum class BreakPoint {
        Compact, 
        Medium,  
        Expanded 
    };

    BreakPoint breakPoint(qreal widthDp);

  private:
    qreal devicePixelRatio; 
};
} // namespace device
} // namespace cf::ui::base

Updated on 2026-03-09 at 10:14:01 +0000