山东大学软件工程应用与实践——WeaselUI(二)

本文详细介绍了C++中的weasel命名空间,解释了其作用和如何使用。同时,文章探讨了FullScreenLayout类如何继承自StandardLayout,而StandardLayout又继承自Layout,展示了类的继承关系。此外,还展示了Layout基类及其主要成员函数,以及StandardLayout类中的一些关键实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2021SC@SDUSC

布局ScreenLayout

FullScreenLayout.h文件

FullScreenLayout.h
#pragma once
#include "StandardLayout.h"

namespace weasel
{
	class FullScreenLayout: public StandardLayout
	{
	public:
		FullScreenLayout(const UIStyle &style, const Context &context, const Status &status, const CRect& inputPos, Layout* layout);
		virtual ~FullScreenLayout();

		virtual void DoLayout(CDCHandle dc);

	private:
		bool AdjustFontPoint(CDCHandle dc, const CRect& workArea, int& fontPoint, int& step);

		const CRect& mr_inputPos;
		Layout* m_layout;
	};
};

weasel命名空间

namespace
命名空间,指标识符的可见范围。C++标准库中的所有标识符都被定义在一个名为 std 的namespace 中。
namesapce简单来说就是用来控制标志符(如变量,函数,类等)的名字冲突的。C++中namespace关键字定义了一个declarative region,所以在一个namespace中声明的标志符和其他namespace中声明的同名标志符是没有名字冲突的。

基本语法

  • 定义命名空间
//举例
namespace zhen{
	int pal;
	void fetch(){
    ...
    }
	//声明一些变量、函数、类等
}
  • 访问namespace中的成员
    * 方法一:using declaration
    * 方法二:using directive
// 方法一:using declaration
namespace zhen{
	int pal;
	void fetch(){
    ...
    }
char pal;// global variable

int main(){
	using zhen::pal;// 一个 using declaration; 它将pal放到了当前的block declarative region,相当于声明了一个局部变量pal
	cin>>pal;//读入局部变量pal
    //double pal; //会报错!因为上条语句已经相当于声明了一个局部变量,这里再声明一个同名的局部变量就会报错
	cin>>::pal;// 读入全局变量pal
}
// 方法二:using directive
namespace zhen{
	int pal;
	void fetch(){
    ...
    }
char pal;// global variable
int main(){
	using namespace zhen;// 就跟平时最常见的“using namespace std;”一样
	double pal;//这里不会报错,而且会覆盖掉zhen::pal
	cin>>pal;//读入局部变量pal
	cin>>zhen::pal;//读入zhen中的pal
	cin>>::pal;//读入全局变量pal
}

类的继承关系

class FullScreenLayout: public StandardLayout 
//FullScreenLayout继承自StandardLayout类
class StandardLayout: public Layout
//StandLayout类又继承自Layout类
  • Layout类
namespace weasel
{
	class Layout
	{
	public:
		Layout(const UIStyle &style, const Context &context, const Status &status);

		virtual void DoLayout(CDCHandle dc) = 0;
		/* All points in this class is based on the content area */
		/* The top-left corner of the content area is always (0, 0) */
		virtual CSize GetContentSize() const = 0;
		virtual CRect GetPreeditRect() const = 0;
		virtual CRect GetAuxiliaryRect() const = 0;
		virtual CRect GetHighlightRect() const = 0;
		virtual CRect GetCandidateLabelRect(int id) const = 0;
		virtual CRect GetCandidateTextRect(int id) const = 0;
		virtual CRect GetCandidateCommentRect(int id) const = 0;
		virtual CRect GetStatusIconRect() const = 0;

		virtual std::wstring GetLabelText(const std::vector<Text> &labels, int id, const wchar_t *format) const = 0;
		virtual bool IsInlinePreedit() const = 0;
		virtual bool ShouldDisplayStatusIcon() const = 0;

	protected:
		const UIStyle &_style;
		const Context &_context;
		const Status &_status;
	};
};
  • StandardLayout类
namespace weasel
{
	const int MAX_CANDIDATES_COUNT = 10;
	const int STATUS_ICON_SIZE = GetSystemMetrics(SM_CXICON);

	class StandardLayout: public Layout
	{
	public:
		StandardLayout(const UIStyle &style, const Context &context, const Status &status);

		/* Layout */
		virtual CSize GetContentSize() const { return _contentSize; }
		virtual CRect GetPreeditRect() const { return _preeditRect; }
		virtual CRect GetAuxiliaryRect() const { return _auxiliaryRect; }
		virtual CRect GetHighlightRect() const { return _highlightRect; }
		virtual CRect GetCandidateLabelRect(int id) const { return _candidateLabelRects[id]; }
		virtual CRect GetCandidateTextRect(int id) const { return _candidateTextRects[id]; }
		virtual CRect GetCandidateCommentRect(int id) const { return _candidateCommentRects[id]; }
		virtual CRect GetStatusIconRect() const { return _statusIconRect; }

		virtual std::wstring GetLabelText(const std::vector<Text> &labels, int id, const wchar_t *format) const;
		virtual bool IsInlinePreedit() const;
		virtual bool ShouldDisplayStatusIcon() const;

	protected:
		/* Utility functions */
		CSize GetPreeditSize(CDCHandle dc) const;
		void UpdateStatusIconLayout(int* width, int* height);

		CSize _contentSize;
		CRect _preeditRect, _auxiliaryRect, _highlightRect;
		CRect _candidateLabelRects[MAX_CANDIDATES_COUNT];
		CRect _candidateTextRects[MAX_CANDIDATES_COUNT];
		CRect _candidateCommentRects[MAX_CANDIDATES_COUNT];
		CRect _statusIconRect;
	};
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值